﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Medical_Store_Billing.Data_Access_Layer;
using Medical_Store_Billing.Object_Class;
using System.Windows.Forms;

namespace Medical_Store_Billing.Business_Login_Layer
{
    class SanphamBLL
    {
        sanphamclass m_sanphamclass = new sanphamclass();
        sanphamDAL m_sanphamdal = new sanphamDAL();

        
        
 //kiem tra sam pham da ton tai hay chua.

        public DataTable Timsp(String masp)
        {
            return m_sanphamdal.Timsp(masp);
        }

        public DataTable Laydssanpham()
        {
            return m_sanphamdal.Laydssanpham1();
        }
        public DataTable Laydssanpham1()
        {
            return m_sanphamdal.Laydssanpham();
        }
        public bool capnhatsoluongsanpham_tuphieunhap(int soluong, String mahang)
        {
            return m_sanphamdal.capnhatsoluongsp_tuphieunhap(soluong, mahang);
        }
        public float Laydongia(String mahang)
        {
            DataTable a = m_sanphamdal.Laydongia(mahang);
            return float.Parse(a.Rows[0][0].ToString());
        }
        public bool capnhatsoluongsanpham_tuphieuxuat(int soluong, String mahang)
        {
            return m_sanphamdal.capnhatsoluongsp_tuphieuxuat(soluong, mahang);
        }
        public int Demsanpham()
        {
            DataRow r = m_sanphamdal.Demsanpham().Rows[0];
            return Int32.Parse(r[0].ToString());
        }
        public bool Themsp(string mahang, string mancc, float gia, string ghichu, int soluong, string tenhang)
        {
            try
            {
                m_sanphamclass = new sanphamclass();

                m_sanphamclass.mahang = mahang;
                m_sanphamclass.mancc = mancc;
                m_sanphamclass.gia = gia;
                m_sanphamclass.ghichu = ghichu;
                m_sanphamclass.soluongcon = soluong;
                m_sanphamclass.tenhang = tenhang;





                return m_sanphamdal.Themsp(m_sanphamclass);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return false;
            }
        }
        public bool Suasp(string mahang, string mancc, float gia, string ghichu, int soluong, string tenhang)
        {
            try
            {
                m_sanphamclass = new sanphamclass();

                m_sanphamclass.mahang = mahang;
                m_sanphamclass.mancc = mancc;
                m_sanphamclass.gia = gia;
                m_sanphamclass.ghichu = ghichu;
                m_sanphamclass.soluongcon = soluong;
                m_sanphamclass.tenhang = tenhang;





                return m_sanphamdal.Suasp(m_sanphamclass);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return false;
            }
        }
    }
}
